package com.cxm.support.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cxm.support.entity.Chart;
import com.cxm.support.entity.Knowledge;
import com.cxm.support.mapper.KnowledgeMapper;
import com.cxm.support.service.KnowledgeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxm.support.vo.DataVO;
import com.sun.scenario.effect.impl.sw.java.JSWBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cxm
 * @since 2022-05-22
 */
@Service
public class KnowledgeServiceImpl extends ServiceImpl<KnowledgeMapper, Knowledge> implements KnowledgeService {
@Autowired
private  KnowledgeMapper knowledgeMapper;

    @Override
    public DataVO findData(String title,String label,Integer page, Integer limit) {
        System.out.println(title);
        if(title==null && label==null) {
            DataVO dataVO = new DataVO();
            dataVO.setCode(0);
            dataVO.setMsg("");
            Page<Knowledge> page2 = new Page<>(page, limit);
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.orderByDesc("id");
            Page<Chart> page3 = knowledgeMapper.selectPage(page2, wrapper);
            dataVO.setCount(page3.getTotal());
            List<Chart> TypecontentList = page3.getRecords();
            dataVO.setData(TypecontentList);
            return dataVO;
        }
        else{
            DataVO dataVO = new DataVO();
            dataVO.setCode(0);
            dataVO.setMsg("");
            Page<Knowledge> page2 = new Page<>(page, limit);
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.orderByDesc("id");
            if(title!=null){
                wrapper.like("title",title);
            }
            if(label!=null){
                wrapper.like("label",label);
            }
            Page<Chart> page3 = knowledgeMapper.selectPage(page2, wrapper);
            dataVO.setCount(page3.getTotal());
            List<Chart> TypecontentList = page3.getRecords();
            dataVO.setData(TypecontentList);
            return dataVO;

        }

    }
}
